package cn.kgc.spring09.service.impl;

import cn.kgc.spring09.mapper.UserMapper;
import cn.kgc.spring09.service.EmpService;
import cn.kgc.spring09.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: mosin
 * @version: v1.0  2022/12/7
 */
@Service("userService")
//@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private EmpService empService;

    /**
        Transactional注解中的属性
           isolation：事务的隔离级别   READ_UNCOMMITTED READ_COMMITTED  REPEATABLE_READ  SERIALIZABLE
           propagation: 事务的传播机制
                 Propagation.REQUIRED  默认
           rollbackFor： 指定回滚的异常
           noRollbackFor: 指定不回滚的异常
     */
    @Transactional(propagation = Propagation.REQUIRED)   // 事务注解
    @Override
    public Integer deleteByUserId(Integer id) {
        Integer integer = userMapper.deleteByUserId(id);
        empService.deleteByEmpNo("7698");
        return integer;
    }

    //@Transactional
    public Integer deleteByUserId2(Integer id) {
        System.out.println(userMapper.getClass());
        Integer integer = userMapper.deleteByUserId(id);
        int a = 1/0;
        return integer;
    }
}
